home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
authors.cl_
/
authors.cl
Wrap
Text File
|
1995-03-12
|
2KB
|
69 lines
Version 1.0 Class
Attribute VB_Name = "clsAuthors"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Option Explicit
Private m_Coll As New Collection
Private m_Database As String
Property Get Count() As Integer
Count = m_Coll.Count
End Property
Property Let DatabaseName(theDatabase As String)
m_Database = theDatabase
End Property
Property Get DatabaseName() As String
DatabaseName = m_Database
End Property
Public Function FillCollection(append As Boolean, Optional theDatabase As Variant) As Integer
Dim db As Database
Dim tbl As Recordset
Dim au As clsAuthor
If Not IsMissing(theDatabase) Then m_Database = theDatabase
If m_Database = "" Then Err.Raise ERR_DATABASENOTSPECIFIED
If append = False Then Clear
Set db = DBEngine.Workspaces(0).OpenDatabase(m_Database)
Set tbl = db.OpenRecordset("Authors")
If tbl.RecordCount > 0 Then
tbl.MoveFirst
Do
Set au = New clsAuthor
au.Initialize tbl
m_Coll.Add Item:=au, key:=CStr(au.AuthorID)
tbl.MoveNext
Loop While Not tbl.EOF
End If
FillCollection = m_Coll.Count
End Function
Public Sub Add(au As clsAuthor)
m_Coll.Add Item:=au, key:=CStr(au.AuthorID)
End Sub
Public Sub Remove(theKey As Long)
m_Coll.Remove CStr(theKey)
End Sub
Public Function Item(theKey As Long) As clsAuthor
Set Item = m_Coll(CStr(theKey))
End Function
Public Sub Clear()
Dim i As Integer
For i = m_Coll.Count To 1 Step -1
m_Coll.Remove i
Next i
End Sub
Public Sub FillList(ctrl As Variant)
Dim i As Integer
ctrl.Clear
For i = 1 To m_Coll.Count
If m_Coll(i).AuthorName <> "" Then
ctrl.AddItem m_Coll(i).AuthorName
Else
ctrl.AddItem "<no name>"
End If
ctrl.ItemData(ctrl.NewIndex) = m_Coll(i).AuthorID
Next i
End Sub